package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr;

import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.iwhalecloud.bss.kite.web.service.accept.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description 雁飞5G缴费周期，账务周期，计费周期，付费类型，是否VIK，VIK业务单编码在用户信息变更展示，其余隐藏
 * @Author deng.gang
 * @Date 2021/8/6 上午11:03
 */
@Service
public class BillingRelatedFieldsHandler extends AbstractAttrHandler {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Autowired
    private IOperateSceneInstService operateSceneInstService;

    @Override
    public void init(CommonAttrVO commonAttr) {
        String sceneInstId = KiteWebContext.getContext().getCurrentSceneInstId();
        String serviceOfferId = querySceneInstService.getSceneInst(sceneInstId).getServiceOfferId();
        if (LocalServiceOfferConsts.SERVICE_OFFER_MOD_USER_INFO.equals(serviceOfferId)) {
            commonAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            KiteAttr attr = querySceneInstService.getCommonAttr(sceneInstId, commonAttr.getFieldName());
            if (Objects.nonNull(attr)) {
                attr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
                operateSceneInstService.setCommonAttr(sceneInstId, attr);
            }
        }
        setCommonAttr(commonAttr);
    }
}
